<?php

//constructor
class db_classes extends dbModel 
{

protected $sSource = "classes";

//get classes (by student_code, module_code or both)
function getClasses($student_code = false, $module_code = false)
{
	
	//if there is no student code given
	if(!$student_code && $module_code) {
		
		//sql query
		$sSql = "SELECT 
					c.class_code 
				FROM 
					classes c, connect_module_class cmc
				WHERE 
					cmc.module_code LIKE '$module_code%' 
				AND 
					cmc.class_code = c.class_code";
		
		$this->trashcan();
		
		//fake de dbModel functie
		$this->run_query($sSql);
		$this->oBench->start_mark();
		$this->iTotal = mysql_num_rows($this->rResult);
		$this->oBench->add_mark('counted rows');
		return $this->iTotal > 0;
	
	//if there is no module code given
	} else if(!$module_code && $student_code) {
		
		//sql query
		$sSql = "SELECT 
					c.class_code
				FROM 
					classes c, connect_student_class csc 
				WHERE 
					csc.student_code LIKE '$student_code%' 
				AND 
					c.class_code = csc.class_code";
		
		$this->trashcan();
		
		//fake de dbModel functie
		$this->run_query($sSql);
		$this->oBench->start_mark();
		$this->iTotal = mysql_num_rows($this->rResult);
		$this->oBench->add_mark('counted rows');
		return $this->iTotal > 0;
	
	//if both are given
	} else if($module_code && $student_code){
	
		//sql query
		$sSql = "SELECT 
					c.class_code 
				FROM 
					classes c, connect_module_class cmc, connect_student_class csc 
				WHERE 
					module_code LIKE '$module_code%' 
				AND 
					c.class_code = cmc.class_code 
				AND 
					csc.student_code LIKE '$student_code%' 
				AND 
					csc.class_code = c.class_code";
		
		$this->trashcan();
		
		//fake de dbModel functie
		$this->run_query($sSql);
		$this->oBench->start_mark();
		$this->iTotal = mysql_num_rows($this->rResult);
		$this->oBench->add_mark('counted rows');
		return $this->iTotal > 0;
		
	} else {
		//do something else
	}
}

public function fetch_classes()
{
	$this->has_many();
}

public function search_classes($sInput)
{
	$this->search($sInput, Array("class_code"));
}
}
?>